package nowcoder.day_48.day4;
import java.util.Scanner;

/**
 * 十进制转N进制
 */
public class Num2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        if (num == 0){
            System.out.println(0);
            return;
        }
        int N = in.nextInt();
        boolean flag = false;
        if (num < 0){
            num = -num;
            flag = true;
        }
        String table = "0123456789ABCDEF";
        StringBuilder sb = new StringBuilder();
        while (num != 0){
            sb.append(table.charAt(num % N));
            num /= N;

        }

        if (flag){
            sb.append("-");
        }
        System.out.println(sb.reverse().toString());
    }
}
